<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>管理</title>
	<meta name="decorator" content="ani"/>
	<style>
		.select-disabled {
			pointer-events: none;
			background-color: #eeeeee;
		}
	</style>
	<script type="text/javascript">

		$(document).ready(function() {

			$("#inputForm").find("select").each(function () {
				if ($(this).attr("data-value") != '' && $(this).attr("data-value") != undefined) {
					$(this).val($(this).attr("data-value"));
				}
			});

			jp.ajaxForm("#inputForm",function(data){
				if(data.success){
				    jp.success(data.msg);
					jp.go("${ctx}/buzz/registwork/registwork");
				}else{
				    jp.error(data.msg);
				    $("#inputForm").find("button:submit").button("reset");
				}
			});

	        $('#regisdate').datetimepicker({
				 format: "YYYY-MM-DD"
		    });
		});

		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			$(list+idx).find(".form_datetime").each(function(){
				 $(this).datetimepicker({
					 format: "YYYY-MM-DD"
			    });
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-md-12">
				<div class="panel panel-primary">
					<div class="panel-heading">
						<h3 class="panel-title">
							<a class="panelButton" href="${ctx}/buzz/registwork/registwork"><i class="ti-angle-left"></i> 返回</a>
						</h3>
					</div>
					<div class="panel-body">
						<form:form id="inputForm" modelAttribute="registwork" action="${ctx}/buzz/registwork/registwork/save" method="post" class="form-horizontal">
							<form:hidden path="id"/>
							<form:hidden path="regisuser.id"/>
							<form:hidden path="nianji"/>
							<fieldset class="well-new">
								<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>基本信息</legend>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">登记日期：</label>
									<div class="col-sm-10 col-md-2">
										<div class='input-group form_datetime' id='regisdate'>
											<input type='text'  name="regisdate" class="form-control "  value="<fmt:formatDate value="${registwork.regisdate}" pattern="yyyy-MM-dd"/>"/>
											<span class="input-group-addon">
												<span class="glyphicon glyphicon-calendar"></span>
											</span>
										</div>
									</div>
									<label class="col-sm-2 col-md-1 control-label">登记人：</label>
									<div class="col-sm-10 col-md-2">
										<form:input path="regisuser.name" htmlEscape="false"  readonly="true"  class="form-control "/>
									</div>
									<label class="col-sm-2 col-md-1 control-label">教室名称：</label>
									<div class="col-sm-10 col-md-2">
										<select id="roor" name="roor.id" class="form-control m-b required" data-value="${registwork.roor.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|教室管理' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">学生姓名：</label>
									<div class="col-sm-10 col-md-2">
										<sys:gridselect url="${ctx}/buzz/student/student/gridselectData" id="student"
														name="student.id" value="${registwork.student.id}"
														labelName="student.name" labelValue="${registwork.student.name}"
														title="学生" cssClass="form-control required"
														fieldLabels="名称|就读学校|就读年级|就读班级|班干"
														fieldKeys="name|schoo.name|grade.name|banji.name|bangan.name"
														searchLabels="名称"
														searchKeys="name"
														relationName="schoo,schoo.id|nianji,grade.id|grade,grade.id|banji,banji.id|bangan,bangan.id"
														conDivIds="roor">
										</sys:gridselect>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">就读学校：</label>
									<div class="col-sm-10 col-md-2">
										<select id="schoo" name="schoo.id" class="form-control m-b required  select-disabled" data-value="${registwork.schoo.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|学校名称' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">就读年级：</label>
									<div class="col-sm-10 col-md-2">
										<select id="grade" name="grade.id" class="form-control m-b required  select-disabled" data-value="${registwork.grade.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|就读年级' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">就读班级：</label>
									<div class="col-sm-10 col-md-2">
										<select id="banji" name="banji.id" class="form-control m-b required  select-disabled" data-value="${registwork.banji.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|班级就读' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
									<label class="col-sm-2 col-md-1 control-label">班干：</label>
									<div class="col-sm-10 col-md-2">
										<select id="bangan" name="bangan.id" class="form-control m-b required  select-disabled" data-value="${registwork.bangan.id}">
											<option value=""></option>
											<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|班干分类' )}" var="dict">
												<option value="${dict.id}">${dict.name}</option>
											</c:forEach>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">备注：</label>
									<div class="col-sm-10 col-md-11">
										<form:textarea path="remarks" htmlEscape="false" rows="4"    class="form-control "/>
									</div>
								</div>
							</fieldset>
							<fieldset class="well-new">
								<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>作业登记</legend>
								<div class="form-group">
									<div id="tab-1" class="tab-pane fade in  active" style="overflow-x: scroll;height: 300px">
										<a class="btn btn-white btn-sm" onclick="addRow('#registworkentryList', registworkentryRowIdx, registworkentryTpl);registworkentryRowIdx = registworkentryRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
										<table class="table table-striped table-bordered table-condensed  text-nowrap">
											<thead>
											<tr>
												<th class="hide"></th>
												<th width="10">操作</th>
												<th style="min-width: 90px;">学科</th>
												<th style="min-width: 90px;">作业分类</th>
												<th style="min-width: 280px;">作业内容</th>
												<th style="min-width: 90px;">完成情况</th>
												<th style="min-width: 90px;">检查结果</th>
												<th style="min-width: 180px;">备注</th>

											</tr>
											</thead>
											<tbody id="registworkentryList">
											</tbody>
										</table>
										<script type="text/template" id="registworkentryTpl">//<!--
												<tr id="registworkentryList{{idx}}">
													<td class="hide">
														<input id="registworkentryList{{idx}}_id" name="registworkentryList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
														<input id="registworkentryList{{idx}}_delFlag" name="registworkentryList[{{idx}}].delFlag" type="hidden" value="0"/>
													</td>
													<td class="text-center" width="10">
														{{#delBtn}}<span class="btn btn-danger"  onclick="delRow(this, '#registworkentryList{{idx}}')"  title="删除">&times;</span>{{/delBtn}}
													</td>
													<td>
														<select id="registworkentryList{{idx}}_xueke" name="registworkentryList[{{idx}}].xueke.id" class="form-control m-b select" data-value="{{row.xueke.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|学科设置' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>


													</td>
													<td>
														<select id="registworkentryList{{idx}}_workjob" name="registworkentryList[{{idx}}].workjob.id" class="form-control m-b select" data-value="{{row.workjob.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|作业分类' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>
													</td>
													<td>
														<input id="registworkentryList{{idx}}_worklr" name="registworkentryList[{{idx}}].worklr" type="text" value="{{row.worklr}}"    class="form-control "/>
													</td>

													<td>
														<select id="registworkentryList{{idx}}_finishwork" name="registworkentryList[{{idx}}].finishwork.id" class="form-control m-b select" data-value="{{row.finishwork.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|完成情况' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>

													</td>


													<td>
														<select id="registworkentryList{{idx}}_janchajieguo" name="registworkentryList[{{idx}}].janchajieguo.id" class="form-control m-b select" data-value="{{row.janchajieguo.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|检查结果' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>
													</td>
													<td>
														<input id="registworkentryList{{idx}}_remarks" name="registworkentryList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control "/>
													</td>

												</tr>//-->
										</script>
										<script type="text/javascript">
											var registworkentryRowIdx = 0, registworkentryTpl = $("#registworkentryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
											$(document).ready(function() {
												var data = ${fns:toJson(registwork.registworkentryList)};
												for (var i=0; i<data.length; i++){
													addRow('#registworkentryList', registworkentryRowIdx, registworkentryTpl, data[i]);
													registworkentryRowIdx = registworkentryRowIdx + 1;
												}
											});
										</script>
									</div>
								</div>
							</fieldset>
							<fieldset class="well-new">
								<legend><i style="padding: 0px 5px 0px 5px" aria-hidden="true"></i>学习进度</legend>
								<div class="form-group">
									<div id="tab-2" class="tab-pane fade in  active" style="overflow-x: scroll;height: 300px">
										<a class="btn btn-white btn-sm" onclick="addRow('#registstudyentryList', registstudyentryRowIdx, registstudyentryTpl);registstudyentryRowIdx = registstudyentryRowIdx + 1;" title="新增"><i class="fa fa-plus"></i> 新增</a>
										<table class="table table-striped table-bordered table-condensed  text-nowrap">
											<thead>
											<tr>
												<th class="hide"></th>
												<th width="10">操作</th>
												<th style="min-width: 90px;">学科</th>
												<th style="min-width: 280px;">课堂内容</th>
												<th style="min-width: 90px;">学习进度</th>
												<th style="min-width: 180px;">备注</th>

											</tr>
											</thead>
											<tbody id="registstudyentryList">
											</tbody>
										</table>
										<script type="text/template" id="registstudyentryTpl">//<!--
												<tr id="registstudyentryList{{idx}}">
													<td class="hide">
														<input id="registstudyentryList{{idx}}_id" name="registstudyentryList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
														<input id="registstudyentryList{{idx}}_delFlag" name="registstudyentryList[{{idx}}].delFlag" type="hidden" value="0"/>
													</td>
													<td class="text-center" width="10">
														{{#delBtn}}<span class="btn btn-danger"  onclick="delRow(this, '#registstudyentryList{{idx}}')"  title="删除">&times;</span>{{/delBtn}}
													</td>
													<td>
														<select id="registstudyentryList{{idx}}_xueke" name="registstudyentryList[{{idx}}].xueke.id" class="form-control m-b select" data-value="{{row.xueke.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|学科设置' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>


													</td>
													<td>
														<sys:gridselect url="${ctx}/basedata/kewenshez/kewenshez/gridselect"
															id="registstudyentryList{{idx}}_kewenshez"
															name="registstudyentryList[{{idx}}].kewenshez.id"
															value ="{{row.kewenshez.id}}"
															labelName="registstudyentryList[{{idx}}].kewenshez.fullname"
															labelValue="{{row.kewenshez.fullname}}"
															title="选择课文设置"
															cssClass="form-control "
															cssStyle="min-width:130px"
															fieldLabels="课文设置|课文主题|单元"
															fieldKeys="name|kwzt|dy.name"
															searchLabels="课文设置|课文主题"
															searchKeys="name|kwzt"
															conDivIds="nianji|registstudyentryList{{idx}}_xueke">
														</sys:gridselect>
														<%--<select id="registstudyentryList{{idx}}_kewenshez" name="registstudyentryList[{{idx}}].kewenshez.id" class="form-control m-b select" data-value="{{row.kewenshez.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|课文设置' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>--%>
													</td>


													<td>
														<select id="registstudyentryList{{idx}}_studyprogress" name="registstudyentryList[{{idx}}].studyprogress.id" class="form-control m-b select" data-value="{{row.studyprogress.id}}">
															<option value=""></option>
																<c:forEach items="${fns:getSelectList('','','bt_base','name','classid|学习进度' )}" var="dict">
																	<option value="${dict.id}">${dict.name}</option>
																</c:forEach>
														</select>
													</td>

													<td>
														<input id="registstudyentryList{{idx}}_remarks" name="registstudyentryList[{{idx}}].remarks" type="text" value="{{row.remarks}}"    class="form-control "/>
													</td>

												</tr>//-->
										</script>
										<script type="text/javascript">
											var registstudyentryRowIdx = 0, registstudyentryTpl = $("#registstudyentryTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
											$(document).ready(function() {
												var data = ${fns:toJson(registwork.registstudyentryList)};



												for (var i=0; i<data.length; i++){
													addRow('#registstudyentryList', registstudyentryRowIdx, registstudyentryTpl, data[i]);
													registstudyentryRowIdx = registstudyentryRowIdx + 1;
												}
											});
										</script>
									</div>
								</div>
							</fieldset>
							<fieldset>
								<legend><i style="padding: 0px 5px 0px 5px" class="fa fa-hand-o-right" aria-hidden="true"></i>附件信息</legend>
								<div class="form-group">
									<label class="col-sm-2 col-md-1 control-label">附件上传：</label>
									<div class="col-sm-10 col-md-11">
										<sys:fileUploadXD path="adjunctFileList" value="${fns:toJson(registwork.adjunctFileList)}"/>
									</div>
								</div>
							</fieldset>
							<c:if test="${mode == 'add' || mode=='edit'}">
								<div class="col-lg-3"></div>
									<div class="col-lg-6">
										<div class="form-group text-center">
											<div>
												 <button class="btn btn-primary btn-block btn-lg btn-parsley" data-loading-text="正在提交...">提 交</button>
											</div>
										</div>
									</div>
							</c:if>
						</form:form>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
